<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ include file="../common/include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>入库</title>


</head>
<body>
<div id="head"><jsp:include page="../common/head.jsp"/></div>
	<div id="body">
	<div id="left">
		<div><jsp:include page="../common/left.jsp"/></div>
		<div></div>
	</div>
	<div id="right"><div>
<form:form commandName="storage" method="post">
<form:hidden path="items.id"/>
<form:hidden path="goods.id"/>
<form:hidden path="category.id"/>
<form:hidden path="handler.id"/>
<form:hidden path="operator.id"/>
<form:hidden path="warehouse.id"/>
<form:hidden path="dealer.id"/>
<form:hidden path="brand.id"/>
<form:hidden path="unit.id"/>

<form:hidden path="items.goodsid"/>
<form:hidden path="items.type" value="1"/>
<form:hidden path="items.cateid"/>
<form:hidden path="items.handlerid"/>
<form:hidden path="items.operatorid"/>
<form:hidden path="items.brandid"/>
<table>
<thead>
</thead>
<tbody>
<tr><td>入库物品名称</td><td><form:input path="goods.name"/><a href="goods/add">+</a><form:errors class="error" path="goods.name" />
</td><td>规格</td><td><form:input path="goods.specification"/><form:errors class="error" path="goods.specification" /> </td>
</tr>
<tr><td>物品所属分类</td><td><form:input path="category.name"/><form:errors class="error" path="goods.categoryId" /></td>
<td></td><td><input id="catetree" type="text" readonly/></td>
</tr>
<tr><td>经办人</td><td><form:input path="handler.name"/><form:errors class="error" path="items.handlerid" /></td>
<td>录入人</td><td><form:input path="operator.name"/><form:errors class="error" path="items.operatorid" /></td>
</tr>
<tr><td>仓库</td><td>
<form:select path="items.warehouseid" items="${warehouseList}" itemValue="code" itemLabel="name"></form:select>
</tr>
<tr><td>经销商</td><td><form:input path="dealer.name"/><form:errors class="error" path="items.dealerid" /></td>
<td>品牌名称</td><td><form:input path="brand.name"/><form:errors class="error" path="items.brandid" /></td>
</tr>
<tr><td>单价(元)</td><td><form:input path="items.price"/><form:errors class="error" path="items.price" /></td>
<td>数量</td><td><form:input path="items.number"/><form:errors class="error" path="items.number" /></td>
</tr><tr><td>总额</td><td><input type=text name="sum"></td><td>单位</td><td><form:input path="unit.name"/></td></tr>
<tr><td>入库日期</td><td><form:input type="date" path="items.handlerDate"/><form:errors class="error" path="items.handlerDate" /></td>
<td>操作时间</td><td><form:input path="items.makeDate" readonly="true"/><form:errors class="error" path="items.makeDate" /></td></tr>
<tr><td>备注</td><td><form:input path="items.note"/><form:errors class="error" path="items.note" /></td>
<td>类型</td>
<td><form:select path="items.reasonid" items="${reasonMap}"></form:select><form:errors class="error" path="items.reasonid" /></td>
</tr>
</tbody>
<tfoot><tr><td><button id="submit" type="button" onclick="storageAddSubmit()">检查</button><button id="submit" type="submit" >提交</button></td>
</tr></tfoot>
</table>
</form:form>
</div></div></div>

</body>
<script type="text/javascript">
	
//提交函数
function storageAddSubmit(){
	var goodsName=$("#goods\\.name").attr("value");
	var goodsSpec=$("#goods\\.specification").attr("value")
	//alert($("#items\\.warehouseid").attr("value"));
	if($("#goods\\.name").attr("value")==""){
		//return false;
	}
	$.post("storage/validate/", $("#storage").serialize(), function(data){
	     alert("Data Loaded: " + data);
	   },"json");
	//form.submit();
}


//options={ 
//serviceUrl:'service/autocomplete.ashx',
//minChars:2, 
// delimiter: /(,|;)\s*/, // regex or character
//maxHeight:400,
//width:300,
// zIndex: 9999,
// deferRequestBy: 0, //miliseconds
// params: { country:'Yes' }, //aditional parameters
// noCache: false, //default is false, set to true to disable caching
// callback function:
// onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
// local autosugest options:
//lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values 
//};
	var goodsOptions, handerOptions,operatorOptions,opt;
	goodsOptions = {
		serviceUrl : 'storage/ajax/',
		onSelect : function(value, data) {
			fillStorage1(value, data);
		},
	};
	handerOptions = {
		serviceUrl : 'staff/user/ajax/',
		onSelect : function(value, data) {
			try{$("#handler\\.id").attr("value",data.id);}catch(e){}
			try{$("#items\\.handlerid").attr("value",data.id);}catch(e){}
		},
	};
	operatorOptions = {
		serviceUrl : 'staff/user/ajax/',
		onSelect : function(value, data) {
			try{$("#operator\\.id").attr("value",data.id);}catch(e){}
			try{$("#items\\.operatorid").attr("value",data.id);}catch(e){}
		},
	};
	$(function() {
		$("#goods\\.name").autocomplete(goodsOptions);
		$("#handler\\.name").autocomplete(handerOptions);
		opt = $("#operator\\.name").autocomplete(operatorOptions);
	});
	
	
	function fillStorage1(value, storage){
		//try{$("#items\\.id").attr("value",storage.goods.id);}catch(e){}
		try{$("#goods\\.id").attr("value",storage.goods.id);}catch(e){}
		try{$("#category\\.id").attr("value",storage.category.id);}catch(e){}
		try{$("#handler\\.id").attr("value",storage.handler.id);}catch(e){}
		try{$("#operator\\.id").attr("value",storage.operator.id);}catch(e){}
		try{$("#warehouse\\.id").attr("value",storage.warehouse.id);}catch(e){}
		try{$("#dealer\\.id").attr("value",storage.dealer.id);}catch(e){}
		try{$("#brand\\.id").attr("value",storage.brand.id);}catch(e){}
		try{$("#unit\\.id").attr("value",storage.unit.id);}catch(e){}
		try{$("#items\\.goodsid").attr("value",storage.goods.id);}catch(e){}
		try{$("#items\\.cateid").attr("value",storage.goods.categoryId);}catch(e){}
		try{$("#items\\.handlerid").attr("value",storage.items.handlerid);}catch(e){}
		try{$("#items\\.operatorid").attr("value",storage.items.operatorid);}catch(e){}
		try{$("#items\\.warehouseid").attr("value",storage.items.warehouseid);}catch(e){}
		try{$("#items\\.brandid").attr("value",storage.items.brandid);}catch(e){}
		
		try{$("#goods\\.name").attr("value",storage.goods.name);}catch(e){}
		try{$("#goods\\.specification").attr("value",storage.goods.specification);}catch(e){}
		try{$("#category\\.name").attr("value",storage.category.name);}catch(e){}
		try{$("#handler\\.name").attr("value",storage.handler.name);}catch(e){}
		try{$("#operator\\.name").attr("value",storage.operator.name);}catch(e){}
		try{$("#warehouse\\.name").attr("value",storage.warehouse.name);}catch(e){}
		try{$("#dealer\\.name").attr("value",storage.dealer.name);}catch(e){}
		try{$("#brand\\.name").attr("value",storage.brand.name);}catch(e){}
		try{$("#unit\\.name").attr("value",storage.unit.name);}catch(e){}
		
		try{$("#items\\.price").attr("value",storage.items.price);}catch(e){}
		try{$("#items\\.number").attr("value",storage.items.number);}catch(e){}
		try{$("#items\\.note").attr("value",storage.items.note);}catch(e){}
		try{$("#items\\.reasonid").attr("value",storage.items.reasonid);}catch(e){}
	}
</script>
</html>